package util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

public class DbUtil {

	static Connection conn = null;
	
	static {
		
		Properties db = new Properties();
		
		InputStream is = DbUtil.class.getResourceAsStream("/db.properties");
		
		try {
			db.load(is);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
		try {
			Class.forName(db.getProperty("driver_class"));
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			conn = DriverManager.getConnection(db.getProperty("url"),db.getProperty("username"),db.getProperty("password"));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("db util static block");
	}
	
	public static Connection getConn() {
		return conn;
	}
}
